package is.web.xdumper.client.table;

import is.bean.entity.NamedEntity;
import is.bean.entity.NamedEntityRemoteAccess;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author aspr0
 */
@Deprecated
public class XdumperEntityTable
{
    public static String generate(Collection<NamedEntityRemoteAccess> remotes) throws RemoteException
    {
        String inputHiddenIdsCount = "<input type=\"hidden\" name=\"idsCount\" value=\"%s\" id=\"idsCount\">";

        String table =
                "<table>"
                + "<thead>%s</thead>"
                + "<tbody>%s</tbody>"
                + "</table>";
        String thead =
                "<tr>"
                + "<td><input type=\"checkbox\" onclick=\"xdtCheckAll(this)\">"
                + "</td>"
                + "<td>Id</td>"
                + "<td>Name</td>"
                + "</tr>";
        String tbody = "";

        Iterator<NamedEntityRemoteAccess> i = remotes.iterator();
        int idNum = 0;

        while (i.hasNext())
        {
            NamedEntity entity = i.next().getNamedEntity();

            /**
             * Form for inputs applied in XdumperWizard
             */
            String tr =
                    "<tr onclick=\"toggleChecked('id" + idNum + "')\">"
                    + "<td>"
                    + "<input "
                    + "type=\"checkbox\" "
                    + "name=\"id" + idNum + "\" "
                    + "id=\"id" + idNum + "\" "
                    + "value=\"" + entity.getId() + "\" "
                    + "onclick=\"toggleChecked('id" + idNum + "')\">"
                    + "</td>"
                    + "<td>" + entity.getId() + "</td>"
                    + "<td>" + entity.getName() + "</td>"
                    + "</tr>";
            tbody += tr;

            idNum++;
        }

        return String.format(table, thead, tbody) + String.format(inputHiddenIdsCount, idNum);
    }
}
